# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=ocaml-yojson
_pkgname=yojson
pkgver=2.0.1
pkgrel=0
pkgdesc="JSON parsing and pretty-printing library for OCaml"
url="https://github.com/ocaml-community/yojson"
arch="all !riscv64"  # limited by ocaml aport
license="BSD-3-Clause"
depends="ocaml-seq"
depends_dev="$pkgname=$pkgver-r$pkgrel ocaml-seq-dev"
makedepends="$depends_dev dune ocaml ocaml-cppo ocaml-findlib"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/ocaml-community/yojson/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"
options="!check" # tests need alcotest library

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	export OCAMLPATH=/usr/lib/ocaml
	dune build @install -p yojson
}

check() {
	dune runtest
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--prefix=/usr \
		--libdir=/usr/lib/ocaml \
		yojson

	# There's just a readme and changelog.
	rm -Rf "$pkgdir"/usr/doc

	# Don't package ydump tool for now.
	rm -Rf "$pkgdir"/usr/bin
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
8b0cd9453a718552f09fe2ce070e82e6b23f463c676a640023d33bf3e97459378680520e80f2db6f365d349c20553e4a78031a3a42e5cbf1a67cce06a6d7f545  ocaml-yojson-2.0.1.tar.gz
"
